import entity.student;

import java.util.*;
import java.util.stream.Collectors;

public class listToMap {
    public static void main(String[] args) {
        //如何把一个list按照一定的类型转化为map
        List<student> studentList = new ArrayList<>();
        studentList.add(new student("张三", "男", 18, 8801));
        studentList.add(new student("张三", "女", 18, 8801));
        studentList.add(new student("李四", "男", 18, 8802));
        studentList.add(new student("王五", "女", 20, 8803));
        studentList.add(new student("赵六", "女", 20, 8804));
        studentList.add(new student("七七", "女", 21, 8805));
        System.out.println("==============只要学生的学号====================");
        List<Integer> studentIds = studentList.stream().map(student::getId).collect(Collectors.toList());
        System.out.println(studentIds.toString());

        System.out.println("==============按照年龄排序===========");
        studentList.stream().sorted(Comparator.comparing(student::getAge).reversed()).collect(Collectors.toList());
        System.out.println(studentList.toString());

        System.out.println("把map按照性别分类");
        Map<String, List<student>> studentGroupBySex = studentList.stream().collect(Collectors.groupingBy(student::getSex));


        System.out.println("=======只要list里面的id列=========");
        List<Integer> ids = studentList.stream().map(student -> student.getId()).distinct().collect(Collectors.toList());
        System.out.println(ids.toString());

        List<student> maleStudent = studentGroupBySex.get("男");
        List<student> femaleStudent = studentGroupBySex.get("女");
        System.out.println("==============打印男同学==============");
        System.out.println(maleStudent.toString());
        System.out.println("==============打印女同学==============");
        System.out.println(femaleStudent.toString());

        System.out.println("==========工作测试=================");
        List<String> nameList = new ArrayList<>();
        nameList.add("刘");
        nameList.add("刘");
        nameList.add("刘");
        nameList.add("刘");
        nameList.add("刘");
        nameList.add("刘");
        nameList.add("李");
        nameList.add("李");
        nameList.add("李");
        nameList.add("李");
        nameList.add("李");
        nameList.add("李");
        Map<String, List<String>> nameClassfy = nameList.stream().collect(Collectors.groupingBy(String::toString));
        for (Map.Entry<String, List<String>> list : nameClassfy.entrySet()) {
            System.out.println(list.getKey() + list.getValue().size());
        }
        System.out.println("===========覆盖掉map里面原始数据============");
        Map<Integer, String> maps = new HashMap<>();
        maps.put(1, "liu");
        System.out.println(maps.toString());
        System.out.println("覆盖后");
        maps.put(1, "zhang");
        System.out.println(maps.toString());
        System.out.println("=======list流排序===============");
        List<Integer> sortList = new ArrayList<>();
        sortList.add(1);
        sortList.add(5);
        sortList.add(2);
        sortList.add(15);
        sortList.add(13);
        sortList.add(9);
        sortList.add(8);
        sortList = sortList.stream().sorted().collect(Collectors.toList());
        System.out.println(sortList.toString());


    }
}
